<template>
  <el-container>
    <el-aside width="200px">
      <el-menu
        default-active="/index"
        class="el-menu-vertical-demo"
        background-color="#ff6040"
        text-color="#fff"
        active-text-color="#ffd04b"
        router
      >
        <el-menu-item index="/index">
          <i class="el-icon-menu"></i>
          <span slot="title">首页</span>
        </el-menu-item>
        <!-- 有children -->
        <template v-for="item in user.menus">
          <el-submenu v-if="item.children" :index="item.title" :key="item.id">
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{item.title}}</span>
            </template>
            <el-menu-item v-for="i in item.children" :key="i.id" :index="`/index/${i.url}`">{{i.title}}</el-menu-item>
          </el-submenu>
          <!-- 没有children -->
          <template v-else>
            <el-menu-item  :key="item.id" :index="`/index/${item.url}`">{{item.title}}</el-menu-item>
          </template>
        </template>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        {{user.username}} |
        <el-button type="text" @click="logout">退出</el-button>
      </el-header>
      <el-main>
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/index/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>{{$route.name}}</el-breadcrumb-item>
        </el-breadcrumb>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
export default {
  mounted() {
    document.title = this.$route.meta.title;
  },
  computed: {
    ...mapGetters({
      user: "user"
    })
  },
  methods: {
    ...mapActions({
      requestUser: "userActions"
    }),
    logout() {
      //退出
      this.requestUser(null);
      this.$router.push("/login");
    }
  }
};
</script>

<style scoped>
.el-header,
.el-footer {
  background-color: #fff;
  color: #333;
  text-align: right;
  line-height: 60px;
}

.el-aside {
  background-color: rgba(0, 0, 0, 0);
  color: #333;
  /* text-align: center;
    line-height: 200px; */
  height: 100vh;
  background-image: linear-gradient(180deg, #ff6040 0%, #ff8a80 100%);
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  /* text-align: center; */
  /* line-height: 160px; */
}
.el-breadcrumb {
  margin-bottom: 20px;
}
</style>